//
//  EFengShareFrame.m
//  WZEfengAndEtong
//
//  Created by wanzhao on 16/2/29.
//  Copyright © 2016年 wanzhao. All rights reserved.
//

#import "EFengShareFrame.h"
#import "EFengShare.h"
#import "EFengPhotosFrame.h"
#import "EFengCommentsFrame.h"
#import "MJExtension.h"
#import "NSAttributedString+ZBTension.h"

@implementation EFengShareFrame

- (void)setShare:(EFengShare *)share
{
    _share = share;
    _headFrame = CGRectMake(10.0f, 10.0f, 40.0f, 40.0f);
    if (share.isFromMineShare) {
        _nameFrame = CGRectMake(CGRectGetMaxX(_headFrame) + 10.0f, 0.0f, 60.0f, 0.0f);
        _timeFrame = CGRectMake(HARDWARE_SCREEN_WIDTH - 20.0f - 100.0f, 0.0f, 100.0f, 0.0f);
    } else {
        _nameFrame = CGRectMake(CGRectGetMaxX(_headFrame) + 10.0f, 10.0f, 60.0f, Font14.lineHeight);
        _timeFrame = CGRectMake(HARDWARE_SCREEN_WIDTH - 20.0f - 100.0f, 10.0f, 100.0f, Font14.lineHeight);
    }
    
    
    
    if (M_ISSTRNULL(share.content)) {
        _contentFrame = CGRectMake(CGRectGetMaxX(_headFrame) + 10.0f, CGRectGetMaxY(_nameFrame), HARDWARE_SCREEN_WIDTH - CGRectGetMaxX(_headFrame) - 30.0f, 0.0f);
        _openFrame = CGRectMake(_contentFrame.origin.x, CGRectGetMaxY(_contentFrame), 80.0f, 0.0f);
    } else {
        CGSize contentSize = [share.attributedText boundingRectWithSize:CGSizeMake(HARDWARE_SCREEN_WIDTH - CGRectGetMaxX(_headFrame) - 30.0f, MAXFLOAT) options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading context:nil].size;
        
        if ([share.attributedText getLineCountWithSize:contentSize] > 6) {
            share.isShowOpenOrHide = YES;
            if (share.isOpen) {
                _contentFrame = CGRectMake(CGRectGetMaxX(_headFrame) + 10.0f, CGRectGetMaxY(_nameFrame) + 10.0f, HARDWARE_SCREEN_WIDTH - CGRectGetMaxX(_headFrame) - 30.0f, (ceilf(contentSize.height)));
                
            } else {
                _contentFrame = CGRectMake(CGRectGetMaxX(_headFrame) + 10.0f, CGRectGetMaxY(_nameFrame) + 10.0f, HARDWARE_SCREEN_WIDTH - CGRectGetMaxX(_headFrame) - 30.0f, (ceilf(Font16.lineHeight * 5)));
            }
            
            _openFrame = CGRectMake(_contentFrame.origin.x, CGRectGetMaxY(_contentFrame) + 5.0f, 80.0f, 35.0f);
            
        } else {
            share.isShowOpenOrHide = NO;
            _contentFrame = CGRectMake(CGRectGetMaxX(_headFrame) + 10.0f, CGRectGetMaxY(_nameFrame) + 10.0f, HARDWARE_SCREEN_WIDTH - CGRectGetMaxX(_headFrame) - 30.0f, (ceilf(contentSize.height)));
            _openFrame = CGRectMake(_contentFrame.origin.x, CGRectGetMaxY(_contentFrame), 80.0f, 0.0f);
            
        }
        
    }
    
    if (share.imageName.count <= 0) {
        EFengPhotosFrame *photos = [[EFengPhotosFrame alloc] init];
        photos.width = HARDWARE_SCREEN_WIDTH - CGRectGetMaxX(_headFrame) - 30.0f;
        photos.height = 0.0f;
        photos.videos = share.videoName;
        photos.Photos = share.imageName ;
        self.photosFrame = photos;
        self.photosFrame.frame = CGRectMake(CGRectGetMaxX(_headFrame) + 10.0f, CGRectGetMaxY(_openFrame), photos.width, photos.height);
        
    } else {
        EFengPhotosFrame *photos = [[EFengPhotosFrame alloc] init];
        photos.width = HARDWARE_SCREEN_WIDTH - CGRectGetMaxX(_headFrame) - 30.0f;
        photos.height = 0.0f;
        photos.videos = share.videoName;
        photos.Photos = share.imageName;
        self.photosFrame = photos;
        self.photosFrame.frame = CGRectMake(CGRectGetMaxX(_headFrame) + 10.0f, CGRectGetMaxY(_openFrame) + 10.0f, photos.width, photos.height);
        
    }
    _toolFrame = CGRectMake(CGRectGetMaxX(_headFrame) + 10.0f, CGRectGetMaxY(self.photosFrame.frame) + 10.0f, HARDWARE_SCREEN_WIDTH - CGRectGetMaxX(_headFrame) - 30.0f, 20.0f);
    
    if (share.praiseArray.count <= 0) {
        _praiseFrame = CGRectMake(10.0f, 0.0f, HARDWARE_SCREEN_WIDTH - CGRectGetMaxX(_headFrame) - 40.0f, 0);
        _commentlineFrame = CGRectMake(0, CGRectGetMaxY(_praiseFrame) + 0.0f, HARDWARE_SCREEN_WIDTH - CGRectGetMaxX(_headFrame) - 20.0f, 0.0f);
    } else {
        CGSize zanSize = [share.zanAttrText boundingRectWithSize: CGSizeMake(HARDWARE_SCREEN_WIDTH - CGRectGetMaxX(_headFrame) - 40.0f, MAXFLOAT) options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading context:nil].size;
        
        _praiseFrame = CGRectMake(10.0f, 5.0f, HARDWARE_SCREEN_WIDTH - CGRectGetMaxX(_headFrame) - 40.0f, zanSize.height);
        _commentlineFrame = CGRectMake(0, CGRectGetMaxY(_praiseFrame) + 5.0f, HARDWARE_SCREEN_WIDTH - CGRectGetMaxX(_headFrame) - 20.0f, 0.5f);
        
        
    }
    
    
    if (share.contentReply.count > 0) {
        EFengCommentsFrame *comments = [[EFengCommentsFrame alloc] init];
        comments.width = HARDWARE_SCREEN_WIDTH - CGRectGetMaxX(_headFrame) - 40.0f;
        comments.height = 0.0f;
        comments.commentsArray = share.contentReply;
        self.commentsFrame = comments;
        self.commentsFrame.frame = CGRectMake(10.0f, CGRectGetMaxY(_commentlineFrame) + 5.0f, comments.width, comments.height);
    } else {
        EFengCommentsFrame *comments = [[EFengCommentsFrame alloc] init];
        comments.width = HARDWARE_SCREEN_WIDTH - CGRectGetMaxX(_headFrame) - 40.0f;
        comments.height = 0.0f;
        comments.commentsArray = share.contentReply;
        self.commentsFrame = comments;
        self.commentsFrame.frame = CGRectMake(10.0f, CGRectGetMaxY(_commentlineFrame), comments.width, comments.height);
    }
    
    _commentViewFrame = CGRectMake(CGRectGetMaxX(_headFrame) + 10.0f, CGRectGetMaxY(_toolFrame) + 5.0f, HARDWARE_SCREEN_WIDTH - CGRectGetMaxX(_headFrame) - 20.0f, CGRectGetMaxY(self.commentsFrame.frame));
    _lineFrame = CGRectMake(0, CGRectGetMaxY(_commentViewFrame) + 9.5f, HARDWARE_SCREEN_WIDTH, 0.5f);
    _cellHeight = CGRectGetMaxY(_lineFrame);
}

@end
